import QtQuick 2.12
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.14
import QtQuick.Window 2.14
import QtMultimedia 5.14
import "./secondPage"
import "./component"

ApplicationWindow {
    id:root
    visible: true
    width: 1024
    height: 600
    maximumWidth: 1024
    maximumHeight: 600
    flags: Qt.Window | Qt.FramelessWindowHint //隐藏标题栏
    x: Screen.width / 2 - width / 2
    y: Screen.height / 2 - height / 2
    title: qsTr("qmlPrint")

    SwipeView{
            id: view
            currentIndex: control.currentIndex
            anchors.fill: parent

            //主页
            SwipeViewPage {
                id: homePage
                color: '#CECDCD'

                 HomePage{
                    anchors.fill: parent
                 }
            }

            //设置size页
            SwipeViewPage {
                id: sizePageView
                color: '#CECDCD'
                SetSizePage{
                   id:sizePage
                   anchors.fill: parent
                   ExNextButton{
                       id:exBtn
                       textName: 'NEXT'
                       anchors.right: parent.right
                       anchors.bottom: parent.bottom
                       anchors.rightMargin:60
                       anchors.bottomMargin: 60
                       MouseArea{
                          anchors.fill: exBtn
                          onPressed: {
                              //playMusic.play();
                              exBtn.anchors.rightMargin-=3;
                          }
                          onReleased: {
                              exBtn.anchors.rightMargin+=3;
                              view.currentIndex+=1;
                          }
                       }
                   }
                }
            }

            //文件页
            SwipeViewPage {
                id: fileView
                color: '#CECDCD'

                FilePage{
                   anchors.fill: parent
                }
            }

            //编辑页
            SwipeViewPage {
                id: editView
                color: '#CECDCD'

                EditPage{
                    id:editgPage
                    anchors.fill: parent
                    ExNextButton{
                       id:exBtn1
                       textName: 'NEXT'
                       anchors.right: parent.right
                       anchors.bottom: parent.bottom
                       anchors.rightMargin:60
                       anchors.bottomMargin: 60
                       MouseArea{
                          anchors.fill: exBtn1
                          onPressed: {
                              //playMusic.play();
                              exBtn1.anchors.rightMargin-=3;
                          }
                          onReleased: {
                              exBtn1.anchors.rightMargin+=3;
                              view.currentIndex+=1;
                          }
                       }
                   }
                }
            }

            //预览页
            SwipeViewPage {
                id: previewView
                color: '#CECDCD'

                PreviewPage{
                   id:previewPage
                   anchors.fill: parent
                   ExNextButton{
                       id:exBtn2
                       textName: 'PRINT'
                       anchors.right: parent.right
                       anchors.bottom: parent.bottom
                       anchors.rightMargin:60
                       anchors.bottomMargin: 60
                       MouseArea{
                          anchors.fill: exBtn2
                          onPressed: {
                              //playMusic.play();
                              exBtn2.anchors.rightMargin-=3;
                              printControl.startPrint(1);
                          }
                          onReleased: {
                              exBtn2.anchors.rightMargin+=3;
                              view.currentIndex = 0;
                          }
                       }
                   }
                }
            }
        }

    //左、右滑动指示器
    PageIndicator {
        id: control
        count: view.count
        currentIndex: view.currentIndex
        anchors.bottom: view.bottom
        anchors.bottomMargin: 20
        anchors.horizontalCenter: parent.horizontalCenter
        spacing: 15
        interactive :true

        delegate: Rectangle {
            implicitWidth: index === control.currentIndex? 20 : 10
            implicitHeight: 10
            radius: implicitHeight / 2
            color: index === control.currentIndex ? "#165DFF" : "#C3C3C3"

            Behavior on opacity {
                OpacityAnimator {
                    duration: 100
                }
            }
        }
    }

    //最小化 退出
    ExWinControl{
      z:200
      x:root.width - 85
      y:5

      onSmallWin: {
         root.visibility = "Minimized"
      }

      onQuitWin: {
         Qt.quit();
      }
    }

    ExPopMsgBox{
        id:popBox
        anchors.centerIn: parent

        modal: true
        title: printControl.errorMsg["type"]
        msg: printControl.errorMsg["msg"]
        visible: false

        Connections{
            target:printControl
            function onErrorMsgChanged(){
                popBox.msg = printControl.errorMsg["msg"]
                popBox.title = printControl.errorMsg["title"]
                popBox.type = printControl.errorMsg["type"]
                popBox.open()
            }
        }
    }

    ExNetCheckBox{
        x:5
        y:root.height - 30
        conected:printControl.netConnected
    }
}
